<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/css.css" rel="stylesheet" type="text/css" />
<link href="css/common.css" rel="stylesheet" type="text/css" />
<link href="css/font-awesome.min.css" rel="stylesheet" type="text/css" />
<script src="js/jquery.min.1.8.2.js" type="text/javascript"></script>
<script src="js/jquery.SuperSlide.2.1.1.js" type="text/javascript"></script>
<script type="text/javascript" src="js/slide.js"></script>
<script src="js/common_js.js" type="text/javascript"></script>
<script src="js/jquery.foucs.js" type="text/javascript"></script>
<script src="http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion=402727"></script>
<script type="text/javascript" src="js/jquery-3.6.0.min.js"></script>
<script type="text/javascript" src="js/axios.min.js"></script>
<!--[if IE 7]>
<link rel="stylesheet" href="assets/css/font-awesome-ie7.min.css">
<![endif]-->
<title>商品详细介绍</title>
</head>
<script>
	const token = sessionStorage.getItem("token");
	$(document).ready(function() {
		    // 页面加载时检查sessionStorage是否有phone值
		    var storedPhone = sessionStorage.getItem('phone');
		    if (storedPhone) {
		        // 如果有，将其插入到id为"login_info"的元素中
		        $('#login_info').text(storedPhone);
		    }
		});
		
		const productDetailDef = sessionStorage.getItem('productDetail');
		const productDetail = JSON.parse(productDetailDef);
		console.log(productDetail);
		console.log(productDetail.productName)
		
		
		// 确保DOM加载完成后再执行
		document.addEventListener('DOMContentLoaded', function() {
		    // 更新商品名称
		    function updateProductName() {
		        const productNameElement = document.getElementsByName('productName')[0];
				const priceElement = document.getElementsByName('price')[0];
				const stockQuantityElement = document.getElementsByName('stock_quantity')[0];
				const brandElement = document.getElementsByName('brand')[0];
				const productIdElement = document.getElementsByName('productIdEle')[0];
				const descriptionElement = document.getElementsByName('description')[0];
		        if (productNameElement) {
		            productNameElement.innerHTML = productDetail.productName;
					priceElement.innerHTML = productDetail.price;
					stackQuant="（库存："+productDetail.stockQuantity+"）";
					stockQuantityElement.innerHTML=stackQuant;
					brandElement.innerHTML=productDetail.brand;
					productNum="商品编号：100000000"+productDetail.productId;
					productIdElement.innerHTML=productNum;
					descriptionElement.innerHTML = productDetail.description;
		        } else {
		            console.error("Element with name 'productName' not found.");
		        }
		    }
		    updateProductName();
		});
		
		function funImage() {
		    var str = '<img src="'+productDetail.imageUrl+'" width="400px" />';
		    $("#detail_main_img").html(str);
		};
		$(document).ready(function() {
			    // 检查detail_main_img里是否有数据，没有就执行funImage函数
			    var detail_main_img = document.getElementById(detail_main_img);
			    if (!detail_main_img) {
					funImage();
				}
			});
			
			// 购买数量
			 function updatenum(action) {
			        var numberInput = document.getElementById('number');
			        var currentValue = parseInt(numberInput.value, 10);
			        if (action === 'increase') {
			            // 增加数量
			            numberInput.value = isNaN(currentValue) ? 1 : currentValue + 1;
			        } else if (action === 'reduce') {
			            // 减少数量，但不能小于1
			            numberInput.value = currentValue > 1 ? currentValue - 1 : 1;
			        }
			    }
	function makeOrder(){
		var numberOr = document.getElementsByName('number')[0].value;
		var priceOr = document.getElementsByName('price')[0].innerText;
		sessionStorage.setItem('numberOr',numberOr);
			sessionStorage.setItem('priceOr',priceOr);
			window.location.href="Orders.html"
		console.log(numberOr,priceOr)
	}
	
const getFormData = () => {
	         return {
				 token,
				 productId:productDetail.productId,
				 number: document.getElementsByName('number')[0].value
	         };
	     };
	 
	     const addCartInfo = () => {
	         // 获取表单数据
	         const formData = getFormData();
	         axios.post("http://localhost:8080/cart/add", formData)
	             .then((response) => {
	                 console.log(response);
						if(response.data){
							alert("添加成功！")
						}else{
							alert("添加失败！")
						}
	             })
	             .catch((error) => {
	                 console.error("添加失败:", error);
	                 // 处理错误情况
	             });
	     };
		 
	
		 
</script>
<body>
<!--顶部样式-->
<div class="top_header">
<em class="left_img"></em>
<div class="header clearfix" id="header">
<div class="header_Section">
 <div class="shortcut">
  <ul>
        <li  class="hd_menu_tit"><a href="user_info.html" id="login_info"></a></li>
   <li  class="hd_menu_tit"><em class="Collect_img"></em><a href="#">收藏夹</a></li>
   <li  class="hd_menu_tit"><em class="cart_img"></em><a href="shopping_cart.html">购物车</a></li>
   <li  class="hd_menu_tit list_name" data-addclass="hd_menu_hover"><a href="#">网站导航</a>
   <em class="navigation_img"></em>
     
    <div class="hd_menu_list">
     <span class="wire"></span>
		
		</div>	
   </li>
  </ul>
 </div>
 <div class="nav" id="Navigation">
  <ul class="Navigation_name"> 
   <li class=""><a href="index.html">首页</a></li>
   <li class=""><a herf="#">浆果类专区</a></li>
   <li class=""><a herf="#">核果类专区</a></li>
   <li class=""><a herf="#">温性水果专区</a></li>
   <li class=""><a herf="#">仁果专区</a></li>
   <li class=""><a herf="#">联系我们</a></li>
  </ul>
 </div>
</div>
</div>
<em class="right_img"></em>
</div>
<!---->
<div></div>
<!--位置-->
<div class="Bread_crumbs">
 <div class="Inside_pages clearfix">
   <div class="left">当前位置：<a href="index.html">首页</a>&gt;<a href="#">详情</a></div>
   <div class="right Search">
   </div>
 </div>
</div>
<!--商品详细介绍-->
<div class="Inside_pages clearfix">
 <!--详细介绍样式-->
 <div class="right_style">
  <div class="pro_detailed">
   <div class="Details_style clearfix" id="goodsInfo">
     <div class="mod_picfold clearfix">
    <div class="clearfix" id="detail_main_img">
		
	</div>
    <div class="Sharing">
     <div class="bdsharebuttonbox right">
         <a href="#" class="bds_more" data-cmd="more"></a>
         <a href="#" class="bds_qzone" data-cmd="qzone" title="分享到QQ空间"></a>
         <a href="#" class="bds_weixin" data-cmd="weixin" title="分享到微信"></a>
         <a href="#" class="bds_tsina" data-cmd="tsina" title="分享到新浪微博"></a>
         <a href="#" class="bds_tqq" data-cmd="tqq" title="分享到腾讯微博"></a>
         <a href="#" class="bds_renren" data-cmd="renren" title="分享到人人网"></a>
         </div>

  <!--收藏-->
	  <div class="coding" name="productIdEle">商品编码：3434534534534534</div>
	 </div>
   </div>
   <!--购买信息-->
    <div class="Buying_info">
      <div class="product_name"><h2 name="productName"></h2></div>
      <div class="product_price">
       <div class="price"><label>商城价：</label><span name="price">￥234.00 </h6><b>元/箱</b></div>
       <div class="jyScore-fra"><span><em style="width:60px;"></em></span><b>4.5</b></div>
      </div>
      <div class="productDL">
        <dl><dt>品种：</dt><dd class="left"><div name="brand"></div></dd></dl>
        <dl><dt>数量：</dt><dd class="left">
        <div class="Numbers">
            <a href="javascript:void(0);" onclick="updatenum('reduce');" class="jian">-</a>
            <input id="number" name="number" type="text" value="1" class="number_text">
            <a href="javascript:void(0);" onclick="updatenum('increase');" class="jia">+</a>
        </div>
        </dd></dl>
		<span class="left Quantity" name="stock_quantity"></span><br/>	<br/>	<br/>	
		<span name="description"></span>
      </div>
      <div class="operating">
       <!-- <button onclick="makeOrder()">立即购买</button> -->
       <a href="#" class="Join_btn" onclick="addCartInfo()"></a>

      </div>
    </div>
   </div>
   <!--信息展示-->
   <div class="mainListRight" id="status1">
   <ul class="fixed_bar" style="">
      <li class="status_on active"><a href="#status1">产品介绍</a></li>
      <li class="status_on"><a href="#status2">商品评价<span>(0)</span></a></li>
      <li class="status_on"><a href="#shbz">售后服务</a></li>
      <div class="statusBtn" style="display: none;"><a href="javascript:addToCart_bak(77)" class="statusBtn1" title="加入购物车"></a></div>
    </ul>
   
   </div>
  </div>
 </div>
</div>
<script>
window._bd_share_config = {
    "common": {
        "bdSnsKey": {},
        "bdText": "",
        "bdMini": "2",
        "bdMiniList": false,
        "bdPic": "",
        "bdStyle": "1",
        "bdSize": "16"
    },
    "share": {},
    "image": {
        "viewList": ["qzone", "weixin", "tsina", "tqq", "renren"],
        "viewText": "分享到：",
        "viewSize": "16"
    },
    "selectShare": {
        "bdContainerClass": null,
        "bdSelectMiniList": ["qzone", "weixin", "tsina", "tqq", "renren"]
    }
};
with(document) 0[(getElementsByTagName('head')[0] || body).appendChild(createElement('script')).src = 'http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion=' + ~(-new Date() / 36e5)];
</script>
</body>
</html>
